var prefix = jsctx + "/memberRefundApply";

var memberRefundApply = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 120;

    function load() {

        var transferType = $("#transferType").val();
        var isVerification = $("#isVerification").val();

        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageMemberRefundApply",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    cache: false,
                    pageSize: 10,
                    pageList: [10, 20, 30],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    rightFixedColumns: true,
                    height: h,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            nickname: $("#nickname").val().trim(),
                            mobile: $("#mobile").val().trim(),
                            refundSource: $("#refundSource").val().trim(),
                            outTradeNo: $("#outTradeNo").val().trim(),
                            refundBy: $("#refundBy").val().trim(),
                            memberMobile: $("#memberMobile").val().trim(),
                            memberRealName: $("#memberRealName").val().trim(),
                            status: $("#status").val().trim(),
                            startTime: $("#startTime").val().trim(),
                            endTime: $("#endTime").val().trim(),
                            wxnickname: $("#wxnickname").val()
                        };
                    },
                    columns: [
                        {
                            checkbox: true, field: '', width: '50', align: 'left',
                            formatter:function (value,row) {
                                //如果已经操作禁止选择。具体可以根据业务
                                if(row.status == 3&&transferType == 1){
                                    //不进行禁用
                                    return { disabled : true}

                                }
                                else if (row.status != 3 && row.status != 0){
                                    return { disabled : true}
                                }

                                else{
                                    //禁用
                                    return { disabled : false}
                                }
                            }
                        },
                        {
                            title: '#', field: '', width: '50', align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },

                        {field: 'nickname', title: '会员名', width: '80', align: 'left'},
                        {field: 'mobile', title: '会员手机号', width: '110', align: 'left'},
                        {
                            field: 'refundSource', title: '发起来源',
                            width: '100', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '公众号'
                                } else if (value == '1') {
                                    return 'APP'
                                } else if (value == '2') {
                                    return '小程序'
                                } else if (value == '3') {
                                    return '运营商后台'
                                }
                            }
                        },
                        {field: 'outTradeNo', title: '提现订单号', width: '150', align: 'left'},
                        {field: 'refundAmount', title: '提现金额（元）', width: '80', align: 'right'},
                        {field: 'account', title: '用户余额', width: '100', align: 'right'},
                        {
                            field: 'refundBy', title: '提现途径',
                            width: '50', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '微信'
                                } else if (value == '1') {
                                    return '支付宝'
                                } else if (value == '2') {
                                    return '银行卡'
                                }
                            }
                        },
                        {field: 'memberMobile', title: '提现账户号码', width: '110', align: 'left'},
                        {field: 'wxnickname', title: '提现昵称', width: '80', align: 'left'},
                        {field: 'memberRealName', title: '对应真实姓名', width: '80', align: 'left'},
                        {
                            field: 'refundBankCode', title: '银行名称',
                            width: '80', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '1002') {
                                    return '工商银行'
                                } else if (value == '1005') {
                                    return '农业银行'
                                } else if (value == '4025') {
                                    return '广州农村商业银行'
                                } else if (value == '4026') {
                                    return '佛山农商银行'
                                } else if (value == '4027') {
                                    return '东莞农村商业银行'
                                } else if (value == '4028') {
                                    return '九江银行股份有限公司'
                                } else if (value == '1003') {
                                    return '建设银行'
                                } else if (value == '1026') {
                                    return '中国银行'
                                } else if (value == '1020') {
                                    return '交通银行'
                                } else if (value == '1001') {
                                    return '招商银行'
                                } else if (value == '1066') {
                                    return '邮储银行'
                                } else if (value == '1006') {
                                    return '民生银行'
                                } else if (value == '1010') {
                                    return '平安银行'
                                } else if (value == '1021') {
                                    return '中信银行'
                                } else if (value == '1004') {
                                    return '浦发银行'
                                } else if (value == '1009') {
                                    return '兴业银行'
                                } else if (value == '1022') {
                                    return '光大银行'
                                } else if (value == '1027') {
                                    return '广发银行'
                                } else if (value == '1025') {
                                    return '华夏银行'
                                } else if (value == '1056') {
                                    return '宁波银行'
                                } else if (value == '4836') {
                                    return '北京银行'
                                } else if (value == '1024') {
                                    return '上海银行'
                                } else if (value == '1054') {
                                    return '南京银行'
                                } else if (value == '4755') {
                                    return '长子县融汇村镇银行'
                                } else if (value == '4216') {
                                    return '长沙银行'
                                } else if (value == '4051') {
                                    return '浙江泰隆商业银行'
                                } else if (value == '4753') {
                                    return '中原银行'
                                } else if (value == '4761') {
                                    return '企业银行（中国）'
                                } else if (value == '4036') {
                                    return '顺德农商银行'
                                } else if (value == '4752') {
                                    return '衡水银行'
                                } else if (value == '4756') {
                                    return '长治银行'
                                } else if (value == '4767') {
                                    return '大同银行'
                                } else if (value == '4115') {
                                    return '河南省农村信用社'
                                } else if (value == '4150') {
                                    return '宁夏黄河农村商业银行'
                                } else if (value == '4156') {
                                    return '山西省农村信用社'
                                } else if (value == '4166') {
                                    return '安徽省农村信用社'
                                } else if (value == '4157') {
                                    return '甘肃省农村信用社'
                                } else if (value == '4153') {
                                    return '天津农村商业银行'
                                } else if (value == '4113') {
                                    return '广西壮族自治区农村信用社'
                                } else if (value == '4108') {
                                    return '陕西省农村信用社'
                                } else if (value == '4076') {
                                    return '深圳农村商业银行'
                                } else if (value == '4052') {
                                    return '宁波鄞州农村商业银行'
                                } else if (value == '4764') {
                                    return '浙江省农村信用社联合社'
                                } else if (value == '4217') {
                                    return '江苏省农村信用社联合社'
                                } else if (value == '4072') {
                                    return '江苏紫金农村商业银行股份有限公司'
                                } else if (value == '4769') {
                                    return '北京中关村银行股份有限公司'
                                } else if (value == '4778') {
                                    return '星展银行（中国）有限公司'
                                } else if (value == '4766') {
                                    return '枣庄银行股份有限公司'
                                } else if (value == '4758') {
                                    return '海口联合农村商业银行股份有限公司'
                                } else if (value == '4763') {
                                    return '南洋商业银行（中国）有限公司'
                                }
                            }
                        },
                        {field: 'createdTime', title: '申请时间', width: '100', align: 'left'},
                        {field: 'paymentTime', title: '到账时间', width: '100', align: 'left'},
                        {
                            field: 'status', title: '提现状态',
                            width: '100', align: 'center',
                            class: 'operateBefore-td',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '未审核'
                                } else if (value == '1') {
                                    return '处理'
                                } else if (value == '2') {
                                    return '已驳回'
                                } else if (value == '3') {
                                    return '提现中'
                                } else if (value == '4') {
                                    return '已到账'
                                } else if (value == '5') {
                                    return '转账失败'
                                }
                            }
                        },
                        {field: 'remark', title: '失败原因', width: '100', align: 'left'},
                        {
                            title: '操作',
                            field: 'roleId',
                            width: '200', align: 'center',
                            class: 'operate-td',
                            formatter: function (value, row, index) {
                                var a = '';
                                var b = '';
                                var c = '';
                                var e = '';
                                if (FinanceManage_refund_update) {
                                    a = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="通过" onclick="memberRefundApply.updateStatusForPass(\''
                                        + row.refundApplyId
                                        + '\')">处理</a> ';
                                    e = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="通过" onclick="memberRefundApply.updateStatusForPassVerification(\''
                                        + row.refundApplyId
                                        + '\')">处理</a> ';
                                    b = '<a class="btn btn-danger btn-sm ' + has_edit + '" href="#" title="" onclick="memberRefundApply.updateStatusForOverrule(\''
                                        + row.refundApplyId
                                        + '\')">驳回</a> ';
                                }
                                if (FinanceManage_refund_look) {
                                    c = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="详情" onclick="memberRefundApply.getMemberRefundApplyDetail(\''
                                        + row.refundApplyId
                                        + '\')">详情</a> ';
                                }
                                var d = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="已到账" onclick="memberRefundApply.updateStatusForArrive(\''
                                    + row.refundApplyId
                                    + '\')">已到账</a> ';

                                if (row.status == 0) {
                                    if (isVerification == 1) {
                                        return a + b;
                                    } else {
                                        return e + b;
                                    }
                                } else if (row.status == 3) {
                                    if (transferType == 1) {

                                        return c;
                                    } else {
                                        return d + b;
                                    }
                                } else {
                                    return c;
                                }

                            }
                        }
                    ]
                });
    }
    function reLoad() {
        $(".fixed-table-header-columns").css("display", "none");
        $(".fixed-table-body-columns").css("display", "none");
        $('#exampleTable').bootstrapTable('refresh');
    }

    function addMemberRefundApply() {
        location.href = prefix + "/addMemberRefundApply";
    }

    function getMemberRefundApplyDetail(refundApplyId) {
        location.href = prefix + "/getMemberRefundApplyDetail/" + refundApplyId;
    }

    var isajaxsendForPass = true;

    function updateStatusForPass(refundApplyId) {
        isajaxsendForPass = false;
        layer.confirm('确认处理此条申请？</br>(确认后请及时根据用户信息联系转账)', {
            btn: ['确定', '取消']
        }, function (index) {
            if (!isajaxsendForPass) {
                $.ajax({
                    url: prefix + "/updateMemberRefundApplyStatus",
                    type: "post",
                    data: {
                        'refundApplyId': refundApplyId,
                        'status': '1'
                    },
                    beforeSend: function () {
                        isajaxsendForPass = true;
                    },
                    success: function (data) {
                        isajaxsendForPass = true;
                        layer.close(index);
                        if (data.status == 200) {
                            layer.msg("处理成功");
                            reLoad();
                        } else {
                            isajaxsendForPass = true;
                            layer.msg(data.message);
                            reLoad();
                        }
                    }
                });
            }
        })
    }

    function updateStatusForPassVerification(refundApplyId) {

        if($('#isVerification').val() == '0'){
        $('#exampleModalVerification').modal('show')

        $("#submitVerificationForm").unbind("click").bind("click", function () {
            var formData = new FormData();
            formData.append("refundApplyId", refundApplyId);
            formData.append("status", "1");
            formData.append("authCode", $("#authCode").val());

            var isajaxVerification = true;

            if (isajaxVerification) {
                $.ajax({
                    url: prefix + "/updateMemberRefundApplyStatus",
                    type: "post",
                    data: formData,
                    dataType: "json",
                    processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                    contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                    beforeSend: function () {
                        isajaxVerification = false;
                    },
                    success: function (data) {
                        if (data.status == 200) {
                            isajaxVerification = true;
                            parent.layer.msg("操作成功");
                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                document.getElementById("contentFormVerification").reset();
                            })
                            $('#exampleModalVerification').modal('hide')
                            reLoad();
                        } else {
                            isajaxVerification = true;
                            parent.layer.alert(data.message);
                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                document.getElementById("contentFormVerification").reset();
                            })
                            $('#exampleModalVerification').modal('hide')
                            reLoad();
                        }

                    }
                })
            }

        })}
        if($('#isVerification').val() == '1'){
            var formData = new FormData();
            formData.append("refundApplyId", refundApplyId);
            formData.append("status", "1");
            var isajaxVerification = true;
            if (isajaxVerification) {
                $.ajax({
                    url: prefix + "/updateMemberRefundApplyStatus",
                    type: "post",
                    data: formData,
                    dataType: "json",
                    processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                    contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                    beforeSend: function () {
                        isajaxVerification = false;
                    },
                    success: function (data) {
                        if (data.status == 200) {
                            isajaxVerification = true;
                            parent.layer.msg("操作成功");
                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                document.getElementById("contentFormVerification").reset();
                            })
                            $('#exampleModalVerification').modal('hide')
                            reLoad();
                        } else {
                            isajaxVerification = true;
                            parent.layer.alert(data.message);
                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                document.getElementById("contentFormVerification").reset();
                            })
                            $('#exampleModalVerification').modal('hide')
                            reLoad();
                        }

                    }
                })
            }
        }
    }


    function updateStatusForOverrule(refundApplyId) {
        $('#exampleModal').modal('show')

        $("#submitForm").unbind("click").bind("click", function () {

            var formData = new FormData();
            formData.append("remark", $("#remark").val());
            formData.append("refundApplyId", refundApplyId);
            formData.append("status", "2");
            $.ajax({
                url: prefix + "/updateMemberRefundApplyStatus",
                type: "post",
                data: formData,
                dataType: "json",
                processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                success: function (data) {
                    if (data.status == 200) {
                        parent.layer.msg("操作成功");
                        $('#exampleModal').on('hidden.bs.modal', function () {
                            document.getElementById("contentForm").reset();
                        })
                        $('#exampleModal').modal('hide')
                        reLoad();
                    } else {
                        parent.layer.alert(data.message);
                        $('#exampleModal').on('hidden.bs.modal', function () {
                            document.getElementById("contentForm").reset();
                        })
                        $('#exampleModal').modal('hide')
                    }

                }
            })
        })
    }


    /*------  验证码  -----*/
    var num1 = 60;
    var ajaxReady = true;

    function getMemberRefundAuthCode() {
        if (ajaxReady) {
            $.ajax({
                url: prefix + "/getMemberRefundAuthCode",
                type: "POST",
                data: $('#authCode').val(),
                beforeSend: function () {
                    ajaxReady = false;
                },
                success: function (data) {
                    if (data.status == 200) {
                        time();

                        function time() {
                            if (num1 == 0) {
                                // $('#authCode').attr("disabled", "disabled")
                                $('#getMemberRefundAuthCode').text("获取验证码");
                                $('#getMemberRefundAuthCode').attr("onclick", 'memberRefundApply.getMemberRefundAuthCode()');
                                ajaxReady = true;
                                num1 = 60;
                            } else {
                                // $('#authCode').removeAttr('disabled')
                                $('#getMemberRefundAuthCode').html(num1 + "秒后重试");
                                $('#getMemberRefundAuthCode').removeAttr('onclick');
                                num1--;
                                setTimeout(function () {
                                    time()
                                }, 1000)
                            }
                        }
                    } else {
                        parent.layer.alert(data.message);
                        $('#authCode').removeAttr('disabled')
                        $('#getMemberRefundAuthCode').text("获取验证码");
                        $('#getMemberRefundAuthCode').attr("onclick", 'memberRefundApply.getMemberRefundAuthCode()');
                        ajaxReady = true;
                        num1 = 60;
                    }

                }
            })


        }
    };

    var isajaxsendForArrive = true;

    function updateStatusForArrive(refundApplyId) {
        if (isajaxsendForArrive) {
            layer.confirm('确认已到账？</br>(确认后将扣除用户余额中对应的提现金额，请确保用户余额充足且用户已收到您的退款)', {
                btn: ['确定', '取消']
            }, function (index) {

                $.ajax({
                    url: prefix + "/updateMemberRefundApplyStatus",
                    type: "post",
                    data: {
                        'refundApplyId': refundApplyId,
                        'status': '3'
                    },
                    beforeSend: function () {
                        isajaxsendForArrive = false;
                    },
                    success: function (data) {
                        isajaxsendForArrive = false;
                        setTimeout(function () {
                            isajaxsendForArrive = true;
                        }, 1500)
                        layer.close(index);
                        if (data.status == 200) {
                            layer.msg("操作成功");
                            reLoad();
                        } else {
                            layer.msg(data.message);
                        }
                    }
                });

            })
        }
    }

    function goBack() {
        window.history.back();
    }

    function exportMemberRefundApply() {
        $.fileDownload(prefix + "/exportMemberRefundApply", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                nickname: $("#nickname").val().trim(),
                mobile: $("#mobile").val().trim(),
                refundSource: $("#refundSource").val().trim(),
                outTradeNo: $("#outTradeNo").val().trim(),
                refundBy: $("#refundBy").val().trim(),
                memberMobile: $("#memberMobile").val().trim(),
                memberRealName: $("#memberRealName").val().trim(),
                status: $("#status").val().trim(),
                startTime: $("#startTime").val().trim(),
                endTime: $("#endTime").val().trim(),
                count: $("#count").val().trim() == '' ? 0 : $("#count").val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }
    function pdselect(){
        var rows = $("#exampleTable").bootstrapTable('getSelections');// 获得要删除的数据
        if (rows.length == 0) {// rows 主要是为了判断是否选中，下面的else内容才是主要
            alert("请先选择要处理的订单!");
            return;
        } else {
            var memberIds = new Array();// 声明一个数组
            var refundAmounts = new Array();
            var refundApplyIds = new Array();
            $(rows).each(function () {// 通过获得别选中的来进行遍历
                memberIds.push(this.memberId); // cid为获得到的整条数据中的一列
                refundAmounts.push(this.refundAmount);
                refundApplyIds.push(this.refundApplyId);
            });
            let sum = 0;
            for (let i=0;i<refundAmounts.length;i++){
                sum = sum + refundAmounts[i];
            }
            memberIdList = JSON.stringify(memberIds);
            refundApplyIdList = JSON.stringify(refundApplyIds);
            memberAdd(memberIdList,memberIds,sum,refundApplyIdList)
        }
    }
    function memberAdd(a,b,c,d) {
        isajaxsendForPass = false;
        var number = b.length;
        // var money = c;
        // var money = Math.round(Math.round((c*100)/100));
       var money = Math.floor(c*100) / 100;
        layer.open({
            title:'批量处理',
            area:['300px','200px'],
            content:'勾选数量:'+ number + '</br>'+ '需退款金额:' + money,
            // + '</br>' + '备注:' + '</br>' + '<textarea id="sefix" rows="4" cols="33"></textarea>'
            btn: ['取消','批量处理','批量驳回',],
                yes:function(index,layero){
                layer.close(index);
                },

                btn2:function(index,layero){
                     // console.log($('#isVerification').val());
                     if($('#isVerification').val() == '0')
                     { $('#exampleModalVerification').modal('show');
                     // console.log($("#sefix").val());
                    // var text = $("#sefix").val();
                    $("#submitVerificationForm").unbind("click").bind("click", function () {
                        var formData = new FormData();
                        formData.append("refundApplyIdsJson",d);
                        formData.append("status", "1");
                        formData.append("authCode", $("#authCode").val());
                        // formData.append("remark", text);
                        var isajaxVerification = true;

                        if (isajaxVerification) {
                            $.ajax({
                                url: prefix + "/batchUpdateMemberRefundApplyStuts",
                                type: "post",
                                data: formData,
                                dataType: "json",
                                processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                                beforeSend: function () {
                                    isajaxVerification = false;
                                },
                                success: function (data) {
                                    // if (data.status == 200 && data.message == null) {
                                    //     isajaxVerification = true;
                                    //     parent.layer.msg("操作成功");
                                    //     $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                    //         document.getElementById("contentFormVerification").reset();
                                    //     })
                                    //     $('#exampleModalVerification').modal('hide')
                                    //     reLoad();
                                    //
                                    // }else if (data.status == 200 && data.message != null){
                                    //     // parent.layer.msg("data");
                                    //     $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                    //         document.getElementById("contentFormVerification").reset();
                                    //     })
                                    //     $('#exampleModalVerification').modal('hide')
                                    //     layer.open({
                                    //         title:'信息提示',
                                    //         area:['300px','300px'],
                                    //         content:data.message,
                                    //         btn: ['确定'],
                                    //         success:function () {
                                    //              reLoad();
                                    //         }
                                    //
                                    // })}
                                    // else {
                                    //     isajaxVerification = true;
                                    //     parent.layer.alert(data.message);
                                    //     $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                    //         document.getElementById("contentFormVerification").reset();
                                    //     })
                                    //     $('#exampleModalVerification').modal('hide')
                                    //     reLoad();
                                    // }
                                    if (data.status == 200 && data.message == "") {
                                        isajaxVerification = true;
                                        parent.layer.msg("操作成功");
                                        $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                            document.getElementById("contentFormVerification").reset();
                                        })
                                        $('#exampleModalVerification').modal('hide');
                                        reLoad();
                                    }
                                    else if(data.status == 200 && data.message != ""){
                                        isajaxVerification = true;
                                        // parent.layer.msg("操作成功");
                                        $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                            document.getElementById("contentFormVerification").reset();
                                        });
                                        $('#exampleModalVerification').modal('hide');
                                        layer.open({
                                            title:'信息提示',
                                            area:['300px','200px'],
                                            content:data.message,
                                            btn: ['确定']

                                        });
                                        reLoad();
                                    }else {
                                        isajaxVerification = true;
                                        parent.layer.alert(data.message);
                                        $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                            document.getElementById("contentFormVerification").reset();
                                        });
                                        $('#exampleModalVerification').modal('hide');
                                        reLoad();
                                    }

                                }
                            })
                        }

                    })}
                    if($('#isVerification').val() == '1'){
                        var formData = new FormData();
                        formData.append("refundApplyIdsJson",d);
                        formData.append("status", "1");
                        var isajaxVerification = true;
                        if (isajaxVerification) {
                            $.ajax({
                                    url: prefix + "/batchUpdateMemberRefundApplyStuts",
                                    type: "post",
                                    data: formData,
                                    dataType: "json",
                                    processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                                    contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                                    beforeSend: function () {
                                        isajaxVerification = false;
                                    },
                                    success: function (data) {
                                        if (data.status == 200 && data.message == "") {
                                            isajaxVerification = true;
                                            parent.layer.msg("操作成功");
                                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                                document.getElementById("contentFormVerification").reset();
                                            })
                                            $('#exampleModalVerification').modal('hide');
                                            reLoad();
                                        }
                                        else if(data.status == 200 && data.message != ""){
                                            isajaxVerification = true;
                                            // parent.layer.msg("操作成功");
                                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                                document.getElementById("contentFormVerification").reset();
                                            })
                                            $('#exampleModalVerification').modal('hide');
                                            layer.open({
                                                title:'信息提示',
                                                area:['300px','200px'],
                                                content:data.message,
                                                btn: ['确定']

                                            });
                                            reLoad();
                                        }
                                        else {
                                            isajaxVerification = true;
                                            parent.layer.alert(data.message);
                                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                                document.getElementById("contentFormVerification").reset();
                                            })
                                            $('#exampleModalVerification').modal('hide')
                                            reLoad();
                                        }
                                    }
                    })}}

                },
                btn3:function(index,layero){

                        $('#exampleModal').modal('show')

                        $("#submitForm").unbind("click").bind("click", function () {

                            var formData = new FormData();
                            formData.append("remark", $("#remark").val());
                            formData.append("refundApplyIdsJson",d);
                            formData.append("status", "2");
                            $.ajax({
                                url: prefix + "/batchUpdateMemberRefundApplyStuts",
                                type: "post",
                                data: formData,
                                dataType: "json",
                                processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                                success: function (data) {
                                    if (data.status == 200 && data.message == "") {
                                        // layer.msg("操作成功");
                                        parent.layer.msg("操作成功");
                                        $('#exampleModal').on('hidden.bs.modal', function () {
                                            document.getElementById("contentForm").reset();
                                        })
                                        $('#exampleModal').modal('hide')
                                        reLoad();
                                    }
                                    else if(data.status == 200 && data.message != "")
                                    {
                                        // layer.msg("请填写备注");
                                        $('#exampleModal').on('hidden.bs.modal', function () {
                                            document.getElementById("contentForm").reset();
                                        })
                                        $('#exampleModal').modal('hide')
                                        layer.open({
                                            title:'信息提示',
                                            area:['300px','200px'],
                                            content:data.message,
                                            btn: ['确定']

                                        })
                                        reLoad();

                                    }
                                    else {
                                        // layer.msg('操作失败');
                                        parent.layer.alert(data.message);
                                        $('#exampleModal').on('hidden.bs.modal', function () {
                                            document.getElementById("contentForm").reset();
                                        })
                                        $('#exampleModal').modal('hide')
                                        reLoad();
                                    }

                                }
                            })
                        })


                }
        }

        )
    }

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        updateStatusForPass: updateStatusForPass,
        updateStatusForOverrule: updateStatusForOverrule,
        addMemberRefundApply: addMemberRefundApply,
        getMemberRefundApplyDetail: getMemberRefundApplyDetail,
        updateStatusForArrive: updateStatusForArrive,
        exportMemberRefundApply: exportMemberRefundApply,
        updateStatusForPassVerification: updateStatusForPassVerification,
        getMemberRefundAuthCode: getMemberRefundAuthCode,
        memberAdd: memberAdd,
        pdselect:pdselect
    };
})();

var addMemberRefundApply = (function () {
    function init() {
        validateRule();
    };

    function getCheckedRoles() {
        var adIds = "";
        $("input:checkbox[name=role]:checked").each(function (i) {
            if (0 == i) {
                adIds = $(this).val();
            } else {
                adIds += ("," + $(this).val());
            }
        });
        return adIds;
    }

    var isajaxsend = true;

    function save() {
        if ($("select[name='refundBy']").val() == "2") {
            if ($("select[name='refundBankCode']").val() == "" || $("select[name='refundBankCode']").val() == null) {
                var str = "<label class='error couponError' ><i class='fa fa-times-circle'></i>请选择银行</label>"
                $(".refundBankCodeDiv").append(str)
                return;
            }
        }


        if (isajaxsend) {
            var formData = new FormData($("#frmMemberRefundApply")[0]);
            $("#roleIds").val(getCheckedRoles());
            $.ajax({
                cache: true,
                type: "POST",
                url: prefix + "/saveMemberRefundApply",
                data: formData,
                processData: false,
                contentType: false,
                async: false,
                beforeSend: function () {
                    isajaxsend = false
                },
                error: function (request) {
                    isajaxsend = true
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.status == 200) {
                        isajaxsend = false
                        parent.layer.msg("操作成功");
                        window.history.back();
                    } else {
                        isajaxsend = true
                        parent.layer.alert(data.message)
                    }

                }
            });
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#frmMemberRefundApply").validate({
            rules: {
                // memberMobile: {
                //     required: true
                // },
                // memberRealName: {
                //     required: true
                // },
                refundAmount: {
                    required: true,
                    min: 1
                },
                refundSource: {
                    required: true,
                },

            },
            messages: {
                // memberMobile: {
                //     required: icon + "请输入提现账户号码"
                // },
                // memberRealName: {
                //     required: icon + "请输入真实姓名"
                // },
                refundAmount: {
                    required: icon + "请输入退款金额",
                    min: icon + "请输入大于1的金额",
                },
                refundSource: {
                    required: icon + "请选择用户充电端",
                },
            },
            submitHandler: function (form) {
                save();
            }
        })
    }

    return {
        init: init
    };
})();
